#include "simpleHandler.h"

////////////////////////////////////////////////////////////
// A nasty down and dirty XML parser that happens to work
// with the NOAA XML returned when using SOAP 1.1 client
// with their SOAP 1.2 server... not a proud bit of code.
//
SimpleHandler::SimpleHandler( QString tag )
{ theTag = tag;
  grabIt = false;
}

SimpleHandler::SimpleHandler( QString tag, bool nameHunt )
{ theName   = tag;
  checkName = false;
  isValue   = false;
  theValue  = -1.0;
}

bool SimpleHandler::startElement( const QString & /* namespaceURI */,
                                  const QString & /* localName */,
                                  const QString &qName,
                                  const QXmlAttributes &attributes )
{ if ( qName == theTag )
    grabIt = true;
  if ( qName.compare( "name", Qt::CaseInsensitive ) == 0 )
    checkName = true;
  if ( qName.compare( "value", Qt::CaseInsensitive ) == 0 )
    isValue = true;
  return true;
}

bool SimpleHandler::endElement  ( const QString & /* namespaceURI */,
                                  const QString & /* localName */,
                                  const QString &qName,
                                  const QXmlAttributes &attributes )
{ return true;
}

bool SimpleHandler::characters(const QString &ch)
{ if ( grabIt )
    { content = ch;
      grabIt = false;
    }
  if (( ch == theName ) && checkName )
    grabValue = true;
  if ( isValue && grabValue )
    { theValue = ch;
      grabValue = false;
    }
  checkName = false;
  isValue   = false;
  return true;
}
